package com.hxzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxzy.controller.anony.dictdata.resp.AnonyDictDataResp;
import com.hxzy.entity.SysDictData;
import com.hxzy.service.SysDictDataService;
import com.hxzy.mapper.SysDictDataMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Administrator
* @description 针对表【sys_dict_data(字典数据表)】的数据库操作Service实现
* @createDate 2024-04-23 20:22:43
*/
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData>
    implements SysDictDataService{


    @Override
    public Map<String, List<AnonyDictDataResp>> findDictTypes(List<String> dictTypes) {
        //lamdba来查询在里面
        // select * from sys_dict_type where  dict_type in (?,?) order by dict_sort 以下是使用mybatis-plus的语法来实现的
        LambdaQueryWrapper<SysDictData>   query = new LambdaQueryWrapper<SysDictData>();
        query.in(SysDictData::getDictType,dictTypes);
        query.orderByAsc(SysDictData::getDictSort);
        List<SysDictData> list = this.list(query);

        Map<String, List<AnonyDictDataResp>> map = list.stream()
                .map(p -> new AnonyDictDataResp(p))
                .collect(Collectors.groupingBy(AnonyDictDataResp::getDictType));

        return map;
    }
}




